<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else
 
//Add tank form option
    include 'watertest.html';
                
    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    switch($_GET['action']) {
        case 'edit':
    
            switch ($_GET['type']) {
            case 'test':                   


            //Function to make a valid date input
            $date = $_POST['year']."-".$_POST['month']."-".$_POST['day'];

            //SQL Query to add tank info
           $qry = "update water_tests set temp='".$_POST['temp']."',dkh= '".$_POST['dkh']."',ph='".$_POST['ph']."',amon='".$_POST['amon']."',mag='".$_POST['mag']."',nitrate='".$_POST['nitrate']."',po4='".$_POST['po4']."',orp='".$_POST['orp']."',cal='".$_POST['cal']."',salinity='".$_POST['salinity']."',sg='".$_POST['sg']."' where test_date = '".$_GET['test_date']."' and user_id='".$_SESSION['uid']."'";

            break;
           }
        break;
      }
        
        //Execute Insert command
        if (!mysql_query($qry,$con))
            {
              die('Error: ' . mysql_error());
            }
            echo "Water test successfully updated!"; 
            echo $qry;
               
    //Close SQL input
    mysql_close($con);
?>
